<?php include '_init_.php';?>
<?php
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';

if($act == 'delete')
{
	if($_REQUEST['worker'])
	{
		$dt = new DataTable(constant('DB_TABLE_WORKER'));
		foreach($_REQUEST['worker'] as $tmpId)
		{
			$dt->remove(intval($tmpId));
		}
	}
}
?>
<?php include 'page_header.php';?>
<div id="main"><!-- start #main //-->
<div id="tita"> <!-- start #tita //-->
<?php define('ADMIN_NAVIGATOR_ITEM','工作人員管理');?>
<?php include 'navigator_admin.php';?>
<?php define('ADMIN_MENU_CURRENT_ITEM','工作人員管理');?>
<?php include 'admin_menu.php';?>

<script language="javascript">
function edit_to_edit(type) {
	var url = '';
	if($('#worker_container_'+type+' input[@type=checkbox][checked]').length == 1)
	{
		url = "backstageci.php?act=edit&type="+type+"&id="+$('#worker_container_'+type+' input[@type=checkbox][checked]').val();
		rAlert(url, null, "工作人員管理", 704, 160);
	}else{
		alert('請選擇一個工作人員');
		return false;
	}
	
}
function edit_to_new(type)
{
	var url = 'backstageci.php?act=new&type='+type;
	rAlert(url, null, "工作人員管理", 704, 160);
}
</script>

<div class="clearfix" id="mainf"><!-- start #mainf //-->
<?php
$dt = new DataTable(constant('DB_TABLE_WORKER'));
$tmp_list = $dt->get_list('','name');
$worker_list = array();
foreach($tmp_list as $tmpData)
{
	$worker_list[$tmpData['type']][] = $tmpData;
}
?>
<?php foreach(unserialize(constant('WORKER_TYPE')) as $typeId=>$workerType):?>
<script language="javascript">
function delete_worder_<?php echo $typeId;?>()
{
	if(confirm('Delete selected')){document.forms['form_workder_<?php echo $typeId;?>'].submit();} 
	return false;
}
</script>
<form name="form_workder_<?php echo $typeId;?>" method="post">
<input type="hidden" name="act" value="delete"/>
<input type="hidden" name="type" value="<?php echo $typeId;?>"/>
<div class="mainf-3" id="worker_container_<?php echo $typeId;?>">
<ul>
      <li class="maina-1i">
        <?php echo $workerType;?>人員管理</li>
        <?php if($worker_list[$typeId]):?>
    	<?php foreach($worker_list[$typeId] as $workerData):?>
    		 <li class="maina-1a"><input type="checkbox"  name="worker[]" value="<?php echo $workerData['id'];?>">&nbsp;<?php echo $workerData['name'];?></li>
    	<?php endforeach;?>
    	<?php endif;?>
        <li class="maina-1d">
        <a onclick="javascript:edit_to_new(<?php echo $typeId;?>);return false;" href="#"><img width="60" height="17" src="images/backstage-btn-5.gif"></a>
        <a onclick="javascript:edit_to_edit(<?php echo $typeId;?>);return false;" href="#"><img width="60" height="17" src="images/backstage-btn-6.gif"></a>
        <a href="#" onclick="return delete_worder_<?php echo $typeId;?>();"><img width="60" height="17" src="images/backstage-btn-7.gif"></a>
        </li>
       </ul>
</div>
</form>
<?php endforeach;?>

</div><!-- end #mainf //-->
</div><!-- end #tita //-->
</div><!-- end #main //-->
<?php include 'page_footer.php';?>